package com.example.mapper;

import com.example.entity.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface StudentMapper {

    // 根据用户名查询学生信息
    @Select("select * from student where username = #{username}")
    Student selectByUsername(String username);

    // 插入学生信息
    @Insert("insert into student (username,password,name,phone,email,class_name,sex,birth,avatar,role)" +
            "values (#{username},#{password},#{name},#{phone},#{email},#{className},#{sex},#{birth},#{avatar},#{role})")
    void insert(Student student);

    // 根据ID更新学生信息
    @Update("update student set username=#{username},password=#{password},name=#{name},phone=#{phone}," +
            "email=#{email},sex=#{sex},birth=#{birth},avatar=#{avatar},class_name=#{className} where id=#{id}")
    void updateById(Student student);

    // 根据ID删除学生信息
    @Delete("delete from student where id= #{id}")
    void deleteById(Integer id);

    // 根据条件查询学生信息列表
    @Select("select * from student where username like concat('%',#{username},'%') and name like concat('%',#{name},'%')")
    List<Student> selectAll(Student student);
}
